package com.cbtx.module.base.ui

import android.app.Activity
import android.os.Bundle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import com.cbtx.module.base.vm.BaseVM
import java.lang.reflect.ParameterizedType

abstract class BaseVMActivity<VM : BaseVM>() : BaseActivity() {

    lateinit var mVM: VM

//    override fun initView(savedInstanceState: Bundle?) {
//         createVM()
//    }

    override fun onCreate(savedInstanceState: Bundle?) {
//        createVM()
        mVM = ViewModelProviders.of(this).get(getPresenterClazz())
        super.onCreate(savedInstanceState)
    }


    abstract fun getPresenterClazz(): Class<VM>

//    private fun createVM(){
//
//        if (mVM == null){
//            var modelClass: Class<*>
//
//            val type = javaClass.genericSuperclass
//
//            modelClass = if (type is ParameterizedType) {
//                type.actualTypeArguments[0] as Class<*>
//            } else {
//                //如果没有指定泛型参数，则默认使用BaseViewModel
//                BaseVM::class.java
//            }
//
//            mVM = ViewModelProviders.of(this).get<ViewModel>(modelClass as Class<ViewModel>) as VM
//        }
//    }
}